package com.walker.elk.netty.websocket.server;


import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.HttpObjectAggregator;
import io.netty.handler.codec.http.HttpServerCodec;
import io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler;
import io.netty.handler.stream.ChunkedWriteHandler;

public class WebSocketServerChannelInitializer extends ChannelInitializer<SocketChannel> {

	@Override
	protected void initChannel(SocketChannel channel) throws Exception {
		
		ChannelPipeline channelPipeline = channel.pipeline();
		
		channelPipeline.addLast(new HttpServerCodec());
		
		channelPipeline.addLast(new ChunkedWriteHandler());
		
		channelPipeline.addLast(new HttpObjectAggregator(8192));
		
		channelPipeline.addLast(new WebSocketServerProtocolHandler("/ws"));
		
		channelPipeline.addLast(new TextWebSocketServerChannelHandler());
	}

}
